# 回合制对战游戏
#  创建角色：名字、性别、血量、装备
#  创建房间：
#  角色可加入房间
#  房间内的人可互打
#  房间上限2人
#
#  战斗
#  装备-防弹衣
#  血量默认100
#  正常被攻击-10滴血
#  有防弹衣-5滴血
import random


class Role(object):
    def __init__(self, name, sex, equipment="locknail", hp=100):
        self.name = name
        self.sex = sex
        self.hp = hp
        self.equipment = equipment
        self.room = None

    def attack(self, other):
        atk = {"普通攻击": 10, "削弱攻击": 5}
        if self == other:
            print("不能攻击自己！")
        else:
            if self.room and self.room == other.room:
                if self.hp <= 0:
                    print("您处于死亡状态，不能攻击")
                elif other.equipment == "locknail":
                    lost_hp = 5
                    print(f"f{other.name}装备着锁子甲")
                else:
                    lost_hp = 10
                other.hp = other.hp - lost_hp
                print(f"{self.name}攻击了{other.name}{lost_hp}点血量，{other.name}当前血量为{other.hp}")
                if other.hp <= 0:
                    print(f"{other.name}已阵亡，无法再进行攻击")
                    exit()
            else:
                print("不在同一房间时不能攻击其他人")


class Room(object):
    max = 2

    def __init__(self, name):
        self.name = name
        self.member_list = []

    def add_member(self, role):
        if role.room is None:
            if len(self.member_list) < 2:
                self.member_list.append(role)
                role.room = self
                print(f"{role.name}加入了{self.name}房间")
        else:
            print(f"{role.name}已加入了{role.room.name}房间")


roles = dict()
rooms = dict()
while 1:
    print("#####################\n"
          "1.创建角色\n"
          "2.创建房间\n"
          "3.加入房间\n"
          "4.开始战斗\n"
          "5.退出\n"
          "#####################")
    option = input("请输入您的操作:")
    if option == "1":
        name, sex = input("请输入角色的姓名于性别，空格分隔:").split()
        roles[name] = Role(name,sex)
    elif option == "2":
        room = input("请输入房间名:")
        rooms[room] = Room(room)
    elif option == "3":
        print(f"当前角色有{roles.keys()},当前房间有{rooms.keys()}")
        role_name, room_name = input("请输入您要加入的角色和房间名，空格分隔:").split()
        rooms[room_name].add_member(roles[role_name])
    elif option == "4":
        while 1:
            first = random.choice([0, 1])
            if first == 0:
                rooms[room_name].member_list[0].attack(rooms[room_name].member_list[1])
            else:
                rooms[room_name].member_list[1].attack(rooms[room_name].member_list[0])
    elif option == "5":
        exit(-1)
    else:
        print("输入有误，请重新开始。")
        continue
